use std::ops::Deref;
use yew_hooks::UseLocalStorageHandle;
use yew_router::navigator::Navigator;
use crate::business::im_router::ImRoute;
use crate::business::websocket::dto::common_dto::LoginCookie;

pub fn to_login(navigator: Navigator) {
    navigator.push(&ImRoute::ToLogin);
}

pub fn get_login_info(local_storage: UseLocalStorageHandle<String>) -> Option<LoginCookie> {
    let local_storage_str = local_storage.deref();
    if let Some(value) = local_storage_str {
        let login_token_json = serde_json::from_str::<LoginCookie>(value);
        log::info!("login_token: {:?}", login_token_json);
        if let Ok(login_cookie) = login_token_json {
           return Some(login_cookie);
        } 
    }
    None
}